//
//  MainView.m
//  2048
//
//  Created by 高新川 on 15/6/7.
//  Copyright (c) 2015年 高新川. All rights reserved.
//

#import "MainView.h"
#import "UIColor+Hex.h"

@implementation MainView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _nowScore = 0;
        [self initView];
    }
    return self;
}

#pragma mark - init view
- (void)initView {
    self.backgroundColor = [UIColor colorWithHexString:@"AAAAAA"];
    self.layer.cornerRadius = 10.0;
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
    _titleLabel.textAlignment = 1;
    _titleLabel.font  = [UIFont systemFontOfSize:15 weight:10];
    _titleLabel.textColor = [UIColor colorWithHexString:@"FDF5E6"];
    [self addSubview:_titleLabel];
    
    _score = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 70, 40)];
    _score.textAlignment = 1;
    _score.font  = [UIFont systemFontOfSize:30 weight:20];
    _score.textColor = [UIColor colorWithHexString:@"FCFCFC"];
    [self addSubview:_score];
}

#pragma mark - public facuation
- (void)setTitle:(NSString *)title andScore:(NSString *)score {
    _titleLabel.text = title;
    _score.text = score;
}

- (void)showScore:(int)add {
    _nowScore = _nowScore + add;
    NSString *text = [NSString stringWithFormat:@"%d",_nowScore];
    _score.text = text;
}

- (void)showHigh:(int)score {
    if (score > _nowScore) {
        _nowScore = score;
        NSString *text = [NSString stringWithFormat:@"%d",_nowScore];
        _score.text = text;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
